package com.sumainfor.pc.gmio.controller.director;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.service.DiComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *投诉中心
 */
@RestController
@RequestMapping("/director/Complaint")
public class DiComplaintController implements Serializable {
    @Autowired
    private DiComplaintService diComplaintService;
    /**
     *查询客户投诉列表 待处理
     */
    @GetMapping("/getDiComplaintListd")
    public JsonResult getDiComplaintListd(@RequestParam Map<String,Object>params,Pager pager){
        String a=params.get("contentList").toString();
        if (a.equals("")) {//是否整租
            params.put("ContentList", null);
        }else{
            params.put("ContentList",  a.split(","));
        }
        System.out.println("接受到的params:"+params);
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=diComplaintService.getDiComplaintCountListd(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getCommunityList=diComplaintService.getDiComplaintListd(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询客户投诉列表 已处理
     */
    @GetMapping("/getDiComplaintListy")
    public JsonResult getDiComplaintListy(@RequestParam Map<String,Object>params,Pager pager){
        String a=params.get("contentList").toString();
        if (a.equals("")) {//是否整租
            params.put("ContentList", null);
        }else{
            params.put("ContentList",  a.split(","));
        }
        System.out.println("接受到的params:"+params);
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=diComplaintService.getDiComplaintCountListy(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getCommunityList=diComplaintService.getDiComplaintListy(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *根据投诉编号查询投诉详情
     */
    @GetMapping("/getDiComplaintInfo")
    public JsonResult getDiComplaintInfod(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        Map<String,Object> map=diComplaintService.getDiComplaintInfo(params);
        if (map!=null){
            result.put(map);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *租后主管提交投诉解决方案
     */
    @PostMapping("/updateDiComplaint")
    public JsonResult updateDiComplaint(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        int count=diComplaintService.updateDiComplaint(params);
        if (count>0){
            result.putSuccess("修改成功");
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *租后主管提交投诉解决方案
     */
    @PostMapping("/addDiComplaint")
    public JsonResult addDiComplaint(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        int count=diComplaintService.addDiComplaint(params);
        if (count>0){
            result.putSuccess("新增成功");
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
}
